package com.hema.auction.adapter;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.hema.auction.R;
import com.hema.auction.activity.SunDetailActivity;
import com.hema.auction.bean.SunSquareInfo;
import com.hema.auction.utils.Constant;
import com.hema.auction.utils.GlideUtils;
import com.hema.auction.utils.Utils;

import java.util.List;

import de.hdodenhof.circleimageview.CircleImageView;

/**
 * 描述:
 * 作者:john
 */
public class SunSquareAdapter extends BaseQuickAdapter<SunSquareInfo, BaseViewHolder> {

    public SunSquareAdapter(@Nullable List<SunSquareInfo> data) {
        super(R.layout.layout_sun_square_item);
    }

    private ItemImageAdapter adapter;
    private boolean showTitle = true;

    public void setShowTitle(boolean showTitle) {
        this.showTitle = showTitle;
    }


    @Override
    protected void convert(BaseViewHolder helper, SunSquareInfo item) {
        CircleImageView ivAvatar = helper.getView(R.id.iv_avatar);
        GlideUtils.load(mContext, item.getFacePic(), ivAvatar);
        helper.setText(R.id.tv_name, item.getUserName());
        helper.setText(R.id.tv_date, Utils.timedate(item.getAddtime()));
        helper.setText(R.id.tv_title, item.getGoodName());
        helper.setVisible(R.id.tv_title, showTitle);
        helper.setText(R.id.tv_desc, item.getContents());
        helper.addOnClickListener(R.id.rv_img);

        RecyclerView recyclerView = helper.getView(R.id.rv_img);
        List<String> imgs = item.getImgs();
        if (imgs != null) {
            recyclerView.setVisibility(View.VISIBLE);
            ItemImageAdapter adapter = new ItemImageAdapter(imgs);
            adapter.setOnItemClickListener(new OnItemClickListener() {
                @Override
                public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                    Bundle bundle = new Bundle();
                    bundle.putParcelable(Constant.EXTRA_SUN_INFO, item);
                    Intent intent = new Intent(mContext, SunDetailActivity.class);
                    intent.putExtras(bundle);
                    mContext.startActivity(intent);
                }
            });
            recyclerView.setAdapter(adapter);
        } else {
            recyclerView.setVisibility(View.GONE);
        }
    }
}
